package com.bjgov.scoresys.service;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.ObjectNotFoundException;

import com.bjgov.scoresys.dao.ProjectDAO;
import com.bjgov.scoresys.entity.Project;
import com.bjgov.scoresys.entity.User;
import com.bjgov.scoresys.util.Page;
import com.bjgov.scoresys.util.PageUtil;
import com.bjgov.scoresys.util.Result;
import com.bjgov.scoresys.util.SendProjectToPlatform;


public class ProjectHandler {
	private static ProjectDAO dao = new ProjectDAO();
	
	public static int addProject(Project entity) {
		return dao.save(entity);
	}
	
	
	public static Project getProject(int id) {
		return dao.findById(id);
	}
	
	public static void updateProject(Project entity) {
		dao.save(entity);
	}
	
	public static void delete(Project entity) {
		dao.delete(entity);
	}
	
	public static Result list(Page page) throws HibernateException,
			ObjectNotFoundException {
		int totalRecords = dao.count();
		page = PageUtil.createPage(page, totalRecords);
		List list = dao.getByPage(page);
		return new Result(list, page);
	}
	
	public static void sendProject(int projectid,String projectName)
	{
		SendProjectToPlatform.send(projectid, projectName);
	}
}
